package com.rabbiter.market.controller.pay;

import com.rabbiter.market.domain.sale.sale_records.SaleRecords;
import com.rabbiter.market.service.pay.PayService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 支付Controller
 * @author lxh
 */
@RestController
@RequestMapping("/pay")
public class PayController {

    @Resource
    private PayService payService;

    @PostMapping("/alipay")
    public void alipay(@RequestBody SaleRecords saleRecords, HttpServletResponse httpResponse) throws Exception {
        payService.alipay(saleRecords, httpResponse);
    }

    @PostMapping("/notify")  // 注意这里必须是POST接口
    public void payNotify(HttpServletRequest request) {
        System.out.println("回调成功");
        if(request.getParameter("trade_status").equals("TRADE_SUCCESS")) {
//            log.info("=====支付宝异步回调成功=====");
//            log.info("{}", request);
            payService.alipayNotify(request);
        }
    }

    /**
     * 支付完成后才能查询到订单
     */
    @GetMapping("/getAliOrder")
    public void getAliOrder() {
        payService.queryOrder("1911608642549964802", null, null, null);
    }

}
